package com.jy.wms.common.base;


import com.joyi.gate.comm.SessionInfo;
import com.joyi.gate.safety.vo.UserInfo;
import com.jy.wms.common.SpringUtil;
import com.jy.wms.dao.WmsShipmentOrderMapper;
import com.jy.wms.pojo.SysHz;
import com.jy.wms.pojo.WmsOwnerShipmentorderconfig;
import com.jy.wms.pojo.WmsShipmentOrder;
import org.jeecgframework.poi.handler.impl.ExcelDataHandlerDefaultImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.List;
import java.util.Map;


public class ShipmentOrderMapImportHanlder extends ExcelDataHandlerDefaultImpl {
    WmsShipmentOrderMapper wmsShipmentOrderMapper = SpringUtil.getBean(WmsShipmentOrderMapper.class);
    private static Logger log = LoggerFactory.getLogger(WmsShipmentOrder.class);
    @Override
    public void setMapValue(Map<String, Object> map, String originKey, Object value) {
        System.out.print("value:" + value);
        log.info("value:" + value);
        /*if (value instanceof Double) {
            map.put(getRealKey(originKey), PoiPublicUtil.doubleToString((Double) value));
        } else {
            map.put(getRealKey(originKey), value != null ? value.toString() : null);
        }*/

        if (value instanceof Double) {
            NumberFormat nf = new DecimalFormat("#");
            value = nf.format(value);

        }

        if(originKey!="" && originKey!=null){
            map.put(getRealKey(originKey), value != null ? value.toString() : null);
        }

    }

    private String getRealKey(String originKey) {
        HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
        HttpSession session = request.getSession();
        UserInfo userinfo = (UserInfo) session.getAttribute(SessionInfo.USER_INFO);//用户信息
        String ckid = String.valueOf(userinfo.getUser().getOrgId().get(0));//仓库id
        List<SysHz> hz = (List) session.getAttribute(BaseSessionInfo.SessionConsignor);
        String hzid = null;
        if (hz.size() > 0) {
            hzid = hz.get(0).getHzid();
        }

        System.out.println("originKey:" + originKey);
        log.info("originKey:" + originKey);
        // WmsOwnerShipmentorderconfig wmsOwnerShipmentorderconfig = wmsShipmentOrderMapper.getWmsShipmentOrderConfig(hzid);

        //if (wmsOwnerShipmentorderconfig != null) {
        if (originKey.equals("渠道名称")) {
            return "qdmc";
        }
        if (originKey.equals("渠道编号")) {
            return "qdbh";
        }
        if (originKey.equals("用途")) {
            return "fylx";
        }
        if (originKey.equals("发运单号")) {//发运编号
            return "fybh";
        }
        if (originKey.equals("客户订单号")) {//客户订单号(总成)
            return "khddh";
        }
        if (originKey.equals("客户编号")) {//客户编号
            return "khbh";
        }
        if (originKey.equals("货品编号")) {//货品编号
            return "hpbh";
        }

        if (originKey.equals("数量")) {
            return "yqsl";
        }

        //  }
        return "";
    }
}
